<?php

namespace App\Http\Controllers;

use App\Http\Requests\TimetableStoreRequest;
use App\Http\Resources\TimetableResource;
use App\Models\Timetable;
use Illuminate\Http\Request;

class TimetableController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Resources\Json\ResourceCollection
     */
    public function index()
    {
        $data = Timetable::all();
        return TimetableResource::collection($data);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  TimetableStoreRequest $request
     * @return TimetableResource
     */
    public function store(TimetableStoreRequest $request)
    {
        $data = $request->all();

        $item = Timetable::create($data);

        return new TimetableResource($item);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  TimetableStoreRequest $request
     * @param  \App\Models\Timetable $timetable
     * @return TimetableResource
     */
    public function update(TimetableStoreRequest $request, Timetable $timetable)
    {
        $data = $request->all();
        $timetable->update($data);
        return new TimetableResource($timetable);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @throws (a)
     * @param  \App\Models\Timetable $timetable
     * @return \Illuminate\Http\Response
     */
    public function destroy(Timetable $timetable)
    {
        $timetable->delete();
        return $this->responseSuccess(null, 204);
    }
}
